<?php


namespace Yeepay\Yop\Sdk\Service\Divide;


use PHPUnit\Framework\TestCase;
use Yeepay\Yop\Sdk\Config\AppSdkConfig;
use Yeepay\Yop\Sdk\Exception\YopClientException;
use Yeepay\Yop\Sdk\Service\Divide\Model as Model;

class DivideClientTest extends TestCase
{

    private static $client;

    public static function setUpBeforeClass()
    {
        // 常用以下两种方式构造client，根据自身情况选择其一
        // 1. 基于本地配置文件方式：支持绝对路径、相对路径(相对于根目录)，适用于将文件打包到项目中，一起部署
        $sdkConfigFile = "yop_sdk_config_default.json";
        self::$client = DivideClientBuilder::builder($sdkConfigFile)->build();

        // 2. 基于json串方式：适用于自定义配置来源，从其他存储加载(比如说数据库、配置中心等)
        //$sdkConfigJson = '{"app_key":"app_xxx","server_root":"https://openapi.yeepay.com/yop-center","yos_server_root":"https://yos.yeepay.com/yop-center","yop_public_key":[{"store_type":"string","cert_type":"RSA2048","value":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6p0XWjscY+gsyqKRhw9MeLsEmhFdBRhT2emOck/F1Omw38ZWhJxh9kDfs5HzFJMrVozgU+SJFDONxs8UB0wMILKRmqfLcfClG9MyCNuJkkfm0HFQv1hRGdOvZPXj3Bckuwa7FrEXBRYUhK7vJ40afumspthmse6bs6mZxNn/mALZ2X07uznOrrc2rk41Y2HftduxZw6T4EmtWuN2x4CZ8gwSyPAW5ZzZJLQ6tZDojBK4GZTAGhnn3bg5bBsBlw2+FLkCQBuDsJVsFPiGh/b6K/+zGTvWyUcu+LUj2MejYQELDO3i2vQXVDk7lVi2/TcUYefvIcssnzsfCfjaorxsuwIDAQAB"}],"isv_private_key":[{"store_type":"string","cert_type":"RSA2048","value":"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCf0qRvP2OJQEONEHiO5Jh2tbGo6pA3Wh7cINgpKZHLHIygZHhB4sU/2JxHqbraRsuBzC2aeWCTrXJVKjQS91vn0JHJd4BonK4ryqTRWULQ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d1KCCZQ9VLaU1ur2+I/erAS+QmIH3MKpmJAoGAP15kpYMr/tE7ENgdH64tFAHp0uWa1kuRrx6JtrnEXXerGlgIeOgT/2fRrxZ0LK7sH9UMF5qRn+MLmIUoJYvA89iWBPrpdNDc9douO1XBu62xXxpUnRy9vQnwKpN4n/pmLa67PwXPbwFna2spQ/z1y1tj0S/yND9SB1qhXGBkhy0CgYBhJf0SZ9PWaasOxAsDgFsj3mSjfvoTqclRDKo1d0KFyOIKOkK3hS8ZaHA/dcR024ydc6b0mU+pyrm2/k+JuX4dHO1M9wshS1YAXytj5RCs+43ghJrbDeNxrNK4VesJPpyK0kEGHSLbMgHnSVZ4/jAgdoKEhz1cHbZorQ92XgDzBw=="}],"encrypt_key":"AWXI5fZGXmTFVHfjyzBMMrrk1IF9dCqGJt3JIZrKY90=","http_client":{"connect_timeout":3000,"read_timeout":30000,"max_conn_total":200,"max_conn_per_route":100}}';
        //self::$client = DivideClientBuilder::builder(new AppSdkConfig(\GuzzleHttp\json_decode($sdkConfigJson, true)))->build();
    }

    /**
     * 申请分账(/rest/v1.0/divide/apply)
     *
     * @test
     */
    public function applyTest()
    {
        $request = new Model\ApplyRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setDivideDetail("[{\"amount\":\"100.00\",\"ledgerNo\":\"10000466938\",\"ledgerType\":\"MERCHANT2MERCHANT\",\"divideDetailDesc\":\"供应商结算\"},{\"amount\":\"100.00\",\"ledgerNo\":\"212345678912\",\"ledgerNoFrom\":\"10000466938\",\"ledgerType\":\"MERCHANT2MEMBER\"}]");
        $request->setAccountLinkInfo("{\"serviceProvider\":\"YEEPAY\",\"ipAddress\":\"192.168.1.1\",\"divideType\":\"1\",\"token\":\"token\"}");
        $request->setIsUnfreezeResidualAmount("isUnfreezeResidualAmount_example");
        try{
            $response = self::$client->apply($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->apply: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 申请分账(/rest/v1.0/divide/apply)
     *
     * @test
     */
    public function apply_v1_0Test()
    {
        $request = new Model\ApplyV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setDivideDetail("[{\"amount\":\"100.00\",\"ledgerNo\":\"10000466938\",\"ledgerType\":\"MERCHANT2MERCHANT\",\"divideDetailDesc\":\"供应商结算\"},{\"amount\":\"100.00\",\"ledgerNo\":\"212345678912\",\"ledgerNoFrom\":\"10000466938\",\"ledgerType\":\"MERCHANT2MEMBER\"}]");
        $request->setAccountLinkInfo("{\"serviceProvider\":\"YEEPAY\",\"ipAddress\":\"192.168.1.1\",\"divideType\":\"1\",\"token\":\"token\"}");
        $request->setIsUnfreezeResidualAmount("isUnfreezeResidualAmount_example");
        try{
            $response = self::$client->apply_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->apply_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 申请分账资金归还(/rest/v1.0/divide/back)
     *
     * @test
     */
    public function backTest()
    {
        $request = new Model\BackRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setDivideBackRequestId("divideBackRequestId_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setDivideBackDetail("[{\"amount\":2.98,\"divideBackReason\":\"用户退款奥\",\"divideDetailNo\":\"1010202411290000016334107323\"}]");
        try{
            $response = self::$client->back($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->back: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 申请余额分账退回(/rest/v1.0/divide/back/apply)
     *
     * @test
     */
    public function backApplyTest()
    {
        $request = new Model\BackApplyRequest();

        $request->setBody(new \Yeepay\Yop\Sdk\Service\Divide\Model\YopBalanceDivideBackReqDTO());
        try{
            $response = self::$client->backApply($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->backApply: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 查询分账资金归还结果(/rest/v1.0/divide/back/query)
     *
     * @test
     */
    public function backQueryTest()
    {
        $request = new Model\BackQueryRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setDivideBackRequestId("divideBackRequestId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        try{
            $response = self::$client->backQuery($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->backQuery: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 分账资金归还回单(/yos/v1.0/divide/back/receipt/download)
     *
     * @test
     */
    public function backReceiptDownloadTest()
    {
        $request = new Model\BackReceiptDownloadRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setDivideBackRequestId("divideBackRequestId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setLedgerNo("ledgerNo_example");
        try{
            $response = self::$client->backReceiptDownload($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->backReceiptDownload: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 查询分账资金归还结果(/rest/v1.0/divide/back/query)
     *
     * @test
     */
    public function back_query_v1_0Test()
    {
        $request = new Model\BackQueryV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setDivideBackRequestId("divideBackRequestId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        try{
            $response = self::$client->back_query_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->back_query_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 分账资金归还回单(/yos/v1.0/divide/back/receipt/download)
     *
     * @test
     */
    public function back_receipt_download_v1_0Test()
    {
        $request = new Model\BackReceiptDownloadV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setDivideBackRequestId("divideBackRequestId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setLedgerNo("ledgerNo_example");
        try{
            $response = self::$client->back_receipt_download_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->back_receipt_download_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 申请分账资金归还(/rest/v1.0/divide/back)
     *
     * @test
     */
    public function back_v1_0Test()
    {
        $request = new Model\BackV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setDivideBackRequestId("divideBackRequestId_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setDivideBackDetail("[{\"amount\":2.98,\"divideBackReason\":\"用户退款奥\",\"divideDetailNo\":\"1010202411290000016334107323\"}]");
        try{
            $response = self::$client->back_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->back_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 申请余额分账(/rest/v1.0/divide/balance/apply)
     *
     * @test
     */
    public function balanceApplyTest()
    {
        $request = new Model\BalanceApplyRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setDivideDetail("[{\"ledgerNo\":\"10080037387\",\"ledgerType\":\"MERCHANT_BIND_CARD\",\"divideAmount\":\"0.1\",\"remark\":\"分账到商户结算卡-附言\",\"feeChargeSide\":\"INSIDE\",\"divideReason\":\"分账到商户结算卡-说明\"}]");
        $request->setBatchNotifyUrl("batchNotifyUrl_example");
        $request->setAccountType("accountType_example");
        $request->setBankAccountBookNo("bankAccountBookNo_example");
        try{
            $response = self::$client->balanceApply($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->balanceApply: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 查询余额分账退回结果(/rest/v1.0/divide/balance/back-query)
     *
     * @test
     */
    public function balanceBackQueryTest()
    {
        $request = new Model\BalanceBackQueryRequest();

        $request->setBody(new \Yeepay\Yop\Sdk\Service\Divide\Model\YopBalanceDivideBackQueryDTO());
        try{
            $response = self::$client->balanceBackQuery($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->balanceBackQuery: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 查询余额分账结果(/rest/v1.0/divide/balance/query)
     *
     * @test
     */
    public function balanceQueryTest()
    {
        $request = new Model\BalanceQueryRequest();

        $request->setDivideRequestId("divideRequestId_example");
        $request->setMerchantNo("merchantNo_example");
        try{
            $response = self::$client->balanceQuery($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->balanceQuery: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 申请余额分账(/rest/v1.0/divide/balance/apply)
     *
     * @test
     */
    public function balance_apply_v1_0Test()
    {
        $request = new Model\BalanceApplyV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setDivideDetail("[{\"ledgerNo\":\"10080037387\",\"ledgerType\":\"MERCHANT_BIND_CARD\",\"divideAmount\":\"0.1\",\"remark\":\"分账到商户结算卡-附言\",\"feeChargeSide\":\"INSIDE\",\"divideReason\":\"分账到商户结算卡-说明\"}]");
        $request->setBatchNotifyUrl("batchNotifyUrl_example");
        $request->setAccountType("accountType_example");
        $request->setBankAccountBookNo("bankAccountBookNo_example");
        try{
            $response = self::$client->balance_apply_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->balance_apply_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 申请余额分账退回(/rest/v1.0/divide/back/apply)
     *
     * @test
     */
    public function balance_divide_back_apply_v1_0Test()
    {
        $request = new Model\BalanceDivideBackApplyV10Request();

        $request->setBody(new \Yeepay\Yop\Sdk\Service\Divide\Model\YopBalanceDivideBackReqDTO());
        try{
            $response = self::$client->balance_divide_back_apply_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->balance_divide_back_apply_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 查询余额分账退回结果(/rest/v1.0/divide/balance/back-query)
     *
     * @test
     */
    public function balance_divide_back_query_v1_0Test()
    {
        $request = new Model\BalanceDivideBackQueryV10Request();

        $request->setBody(new \Yeepay\Yop\Sdk\Service\Divide\Model\YopBalanceDivideBackQueryDTO());
        try{
            $response = self::$client->balance_divide_back_query_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->balance_divide_back_query_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 查询余额分账结果(/rest/v1.0/divide/balance/query)
     *
     * @test
     */
    public function balance_query_v1_0Test()
    {
        $request = new Model\BalanceQueryV10Request();

        $request->setDivideRequestId("divideRequestId_example");
        $request->setMerchantNo("merchantNo_example");
        try{
            $response = self::$client->balance_query_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->balance_query_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 完结分账(/rest/v1.0/divide/complete)
     *
     * @test
     */
    public function completeTest()
    {
        $request = new Model\CompleteRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setDivideDetailDesc("divideDetailDesc_example");
        try{
            $response = self::$client->complete($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->complete: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 完结分账(/rest/v1.0/divide/complete)
     *
     * @test
     */
    public function complete_v1_0Test()
    {
        $request = new Model\CompleteV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setDivideDetailDesc("divideDetailDesc_example");
        try{
            $response = self::$client->complete_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->complete_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 查询分账结果(/rest/v1.0/divide/query)
     *
     * @test
     */
    public function queryTest()
    {
        $request = new Model\QueryRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        try{
            $response = self::$client->query($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->query: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 查询分账结果(/rest/v1.0/divide/query)
     *
     * @test
     */
    public function query_v1_0Test()
    {
        $request = new Model\QueryV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        try{
            $response = self::$client->query_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->query_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 分账回单(/yos/v1.0/divide/receipt/download)
     *
     * @test
     */
    public function receiptDownloadTest()
    {
        $request = new Model\ReceiptDownloadRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setLedgerNo("ledgerNo_example");
        try{
            $response = self::$client->receiptDownload($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->receiptDownload: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 分账回单(/yos/v1.0/divide/receipt/download)
     *
     * @test
     */
    public function receipt_download_v1_0Test()
    {
        $request = new Model\ReceiptDownloadV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setLedgerNo("ledgerNo_example");
        try{
            $response = self::$client->receipt_download_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling DivideClient->receipt_download_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
}
